package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.MenuMapper;
import com.aaa.hospital.pojo.query.MenuQuery;
import com.aaa.hospital.pojo.vo.MenuVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: danghui
 * @Date: 2022/2/22 17:42
 * @Description: TODO
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public AjaxResult listMenu(MenuQuery query) {
        List<MenuVO> menuVOS = menuMapper.listMenu(query);
        Long along = menuMapper.listMenuTotal(query);
        HashMap<Object, Object> data = new HashMap<>();
        data.put("currentData",menuVOS);
        data.put("totalCount",along);
        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult deleteMenu(Integer id) {
        int i = menuMapper.deleteMenu(id);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult addMenu(MenuVO menuVO) {
        int i = menuMapper.addMenu(menuVO);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult getMenu(Integer id) {
        MenuVO menuVO = menuMapper.getMenu(id);
        return AjaxResult.success(menuVO);
    }

    @Override
    public AjaxResult updateMenu(MenuVO menuVO) {
        int i = menuMapper.updateMenu(menuVO);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }
}
